
package cn.gxa.j229.bug.finance.service.borrowing.impl;

import cn.gxa.j229.bug.finance.mapper.LoanMapper;
import cn.gxa.j229.bug.finance.mapper.SignMapper;
import cn.gxa.j229.bug.finance.pojo.Loan;
import cn.gxa.j229.bug.finance.pojo.Sign;

import cn.gxa.j229.bug.finance.service.borrowing.SignService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 *
 * @Author FanJiang
 * @Date 2020/9/22
 * @Version 1.0
 */


@Service("signService")
public class SignServiceImpl implements SignService {

    @Resource
    SignMapper signMapper;
    @Resource
    LoanMapper loanMapper;

    @Override
    public int insertSelective(Sign sign) {
        return signMapper.insertSelective(sign);
    }
    @Transactional(propagation = Propagation.SUPPORTS,isolation = Isolation.DEFAULT,rollbackFor = {Throwable.class})
    @Override
    public int updateSelective(Sign sign) {
        loanMapper.updateStateBynum(sign.getNum());
        return signMapper.updateByPrimaryKeySelective(sign);
    }

    /**
     * 标的上架
     * 分页查询and多条件模糊查询
     * @param loan 接收一个loan对象
     * @return
     */
    @Override
    public List<Map<String, Object>> findByUnionPage(Loan loan) {
        loan.setLimit((loan.getLimit() - 1) * loan.getPage());
        return signMapper.findByUnionPage(loan);
    }

    /**
     * 标的上架
     * 总记录数统计
     * @param loan
     * @return
     */
    @Override
    public Integer countPage(Loan loan) {
        return signMapper.countForSignSver(loan);
    }


}

